package com.linhsu.genealogy.model;

import java.util.Collection;
import java.util.HashSet;

import com.linhsu.genealogy.model.listener.NoteListener;

public final class Note extends GenealogyElement {

	private String text = "";
	private final Collection<NoteListener> listeners = new HashSet<NoteListener>();
	
	public Note() {
	}

	public Note(String text) {
		
	}
	
	public String getText() {
		return text;
	}
	
	public boolean setText(String newText) {
		if (newText == null)
			newText = "";
		if (newText.equals(text))
			return false;
		text = newText;
		for (NoteListener l : listeners)
			l.textChanged(text);
		return true;
	}
	
	// add and remove listeners
	
	public void addNoteListener(NoteListener l) {
		listeners.add(l);
	}
	
	public void removeNoteListener(NoteListener l) {
		listeners.remove(l);
	}
	
	//GelealogyElement's method
	
	@Override
	protected void fireLocationChanged(int newX, int newY) {
		// TODO Auto-generated method stub
		for (NoteListener l : listeners)
			l.locationChanged(newX, newY);
	}

	@Override
	protected void fireSizeChanged(int newWidth, int newHeight) {
		// TODO Auto-generated method stub
		for (NoteListener l : listeners)
			l.sizeChanged(newWidth, newHeight);
	}

}
